/**
 * 
 */
package com.googlecode.eventio.examples.chat;


/**
 * @author steph
 * 
 */
public class ChatMain {

	private final StringInputResource promptResource = new StringInputResource();

	private final ChatService chatService = new ChatService();

	private enum Command {
		folow, post
	}

	public ChatMain() {
	}

	public void start() {
		System.out.println("Enter message like: msg <user> text message");
		System.out.println("Or quit to exit.");

		chatService.folow("bigfan", "rocky");
		chatService.folow("bigfan2", "rocky");

		String command = prompt();
		while (!"quit".equals(command)) {

			String[] commands = command.split(" ");
			switch (Command.valueOf(commands[0])) {
			case post:
				chatService.post("rocky", command);
				break;
			}

			command = prompt();
		}
	}

	private String prompt() {
		System.out.print("message: ");

		return promptResource.call();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new ChatMain().start();
	}

}
